package com.one.consumer.common.extra;


import com.amap.api.location.AMapLocation;
import com.one.common.model.extra.BaseExtra;
import com.one.common.utils.StringUtils;

/**
 * 地址传递参数对象
 */

public class LocationExtra extends BaseExtra {
    private String cityName;     // 市名
    private String lastName;     // 最后的名字
    private String backwards2Name; // 倒数2个名字
    private double latitude;
    private double longitude;   // 经纬度
    private String address;     // 详细地址
    private String title;       // 简短地址
    private String adCode;      // 城市id

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAdCode() {
        return adCode;
    }

    public void setAdCode(String adCode) {
        this.adCode = adCode;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getBackwards2Name() {
        return backwards2Name;
    }

    public void setBackwards2Name(String backwards2Name) {
        this.backwards2Name = backwards2Name;
    }


    /**
     * AMapLocation转换成CityAndLocationExtra
     */
    public static LocationExtra getExtra(AMapLocation aMapLocation) {
        if (aMapLocation != null && aMapLocation.getCity() != null) {
            String backwards2Name = StringUtils.appendWithSpace(aMapLocation.getCity(), aMapLocation.getDistrict());
            LocationExtra cityAndLocationExtra = new LocationExtra();
            cityAndLocationExtra.setCityName(aMapLocation.getCity());
            cityAndLocationExtra.setAdCode(aMapLocation.getAdCode());
            String address = aMapLocation.getAddress();
            if (StringUtils.isNotBlank(address)) {
                address = address.replace(aMapLocation.getCity(), "").replace(aMapLocation.getProvince(), "").replace(aMapLocation.getDistrict(), "");
            }
            cityAndLocationExtra.setAddress(address);
            cityAndLocationExtra.setBackwards2Name(backwards2Name);
            cityAndLocationExtra.setLatitude(aMapLocation.getLatitude());
            cityAndLocationExtra.setLongitude(aMapLocation.getLongitude());
            return cityAndLocationExtra;
        }
        return null;
    }

    @Override
    public String toString() {
        return "LocationExtra{" +
                "cityName='" + cityName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", backwards2Name='" + backwards2Name + '\'' +
                ", latitude='" + latitude + '\'' +
                ", longitude='" + longitude + '\'' +
                ", address='" + address + '\'' +
                ", adCode='" + adCode + '\'' +
                '}';
    }
}
